/*
 * @Date: 2022-02-23 17:00:19
 * @LastEditors: wuyuxin
 * @LastEditTime: 2022-02-23 17:03:42
 * @FilePath: \webpack-learning\26_自定义Loader\loaders\hybabel-loader.js
 * @description: 文件描述
 */
const babel = require('@babel/core')
const { getOptions } = require('loader-utils')

module.exports = function(content) {
  // 设置为异步loader
  const callback = this.async()
  // 获取传入的参数
  const options = getOptions(this);
  // 对源代码进行转换
  babel.transform(content, options, (err, result) => {
    if (err) {
      callback(err);
    } else {
      callback(null, result.code)
    }
  })
}